---
- name: Ensure config dir
  ansible.builtin.file:
    path: "{{ nvim_config_dir }}"
    state: directory

- name: Install nvim in Linux
  ansible.builtin.import_tasks: linux.yml
  when: ansible_distribution == "Ubuntu" or ansible_distribution == "Debian"

- name: Install nvim in macOS
  ansible.builtin.import_tasks: macos.yml
  when: ansible_distribution == "MacOSX"

- name: Backup nvim main conf
  ansible.builtin.copy:
    src: "{{ nvim_config_dir }}"
    dest: "{{ nvim_config_dir }}.bak"
    remote_src: true

- name: Remove prev nvim conf
  ansible.builtin.file:
    path: "{{ nvim_config_dir }}"
    state: absent

- name: Install astronvim
  ansible.builtin.git:
    repo: "{{ nvim_repo }}"
    dest: "{{ nvim_config_dir }}"
    depth: 1
    clone: true
    force: true
